package com.studiocode.aspeaker;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;

public class AppVersion
{

	public static String getVersionName(Context context, Class cls) 
	{
	  try
	  {
		ComponentName comp = new ComponentName(context, cls);
		PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
		return pinfo.versionName;
	  }
	  catch (android.content.pm.PackageManager.NameNotFoundException e)
	  {
	    return null;
	  }
	}
	
	public static boolean getInDebugMode(Context context, Class cls) 
	{
	  try
	  {
	    ComponentName comp = new ComponentName(context, cls);
	    PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
	    ApplicationInfo myAppInfo = pinfo.applicationInfo;

	    if ( 0 != (myAppInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE))
	      return true;
	    else
	      return false;
	  }
	  catch (android.content.pm.PackageManager.NameNotFoundException e)
	  {
	    return false;
	  }
	}
}

